home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: initializeQueues.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:38 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
- #include "queue_consist.h"
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "list.h"
- #include "error.h"
- #include "tid.h"
- #include "pool.h"
- #include "io.h"
- #include "bitvec.h"
- #include "lock.h"
- #include "msgdefs.h"
- #include "disk.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "latch.h"
- #include "bf.h"
- #include "link.h"
- #include "volume.h"
- #include "trace.h"
- #include "msgvector.h"
- #include "disk_funcs.h"
- #include "disk_globals.h"
- #include "io_globals.h"
- #include "msg_globals.h"
- #include "sharedmem_globals.h"
- #include "queue_globals.h"
-
- #ifdef DEBUG
- void
- dumpQueue( QUEUEPAIR *q )
- {
- register int n;
-
- fprintf(stderr,
- "q 0x%x, to.magic 0x%x to.mutex.magic 0x%x, from.magic 0x%x, from.mutex.magic 0x%x",
- q, q->toDisk.magic, q->toDisk.mutex.magic, q->fromDisk.magic,
- q->fromDisk.mutex.magic );
- n = q->toDisk.front - q->toDisk.back;
- if (n<0) n = 0-n;
- fprintf(stderr, "\tTO: %d ",n);
- n = q->fromDisk.front - q->fromDisk.back;
- if (n<0) n = 0-n;
- fprintf(stderr, "\tFROM: %d ",n);
- fprintf(stderr, "\n");
- } /* dumpQ */
- #endif DEBUG
-
-
- QUEUEPAIR *
- _diskQueue(int i, BOOL check)
- {
- QUEUEPAIR *qp = (QUEUEPAIR *)(ShmDiskQueues + (i * QPairSize));
-
- if(check) {
- CHECK_QUEUE_MAGIC(&(qp->fromDisk));
- CHECK_QUEUE_MAGIC(&(qp->toDisk));
- }
-
- return qp;
- }
-
-
- QUEUEPAIR *
- diskQueue(int i)
- {
- return _diskQueue(i, TRUE);
- }
-
- QUEUEPAIR *
- initDiskQueue(int i, VOLREC *volRec)
- {
- QUEUEPAIR *qp;
-
- qp = _diskQueue(i, FALSE);
- bzero((char *)qp, sizeof (QUEUEPAIR));
-
- qp->volRec = volRec;
- qp->semNum = i;
-
- INIT_QUEUE_MAGIC(&(qp->toDisk));
- INIT_QUEUE_MAGIC(&(qp->fromDisk));
- /*
- * Initialize the array of elements.
- * First make elements point to the rest of the space
- * between this disk q and the next.
- * The amount of space here should be sizeof(ShmOffset)*NumMsgBufs.
- */
- qp->elements = (ShmOffset)(&qp->elements);
- qp->elements++;
-
- return qp;
- }
-
- void
- initializeQueues()
- {
- /*
- * this relies on bf_Initialize() already
- * having got all the shared memory and set the offset.
- */
- #ifdef DISKPROC_MAKE
- error -- this is for server only --
- the disk process does not have volRecs and such.
- #endif DISKPROC_MAKE
-
- TRACE(TR_INIT, TR_LEVEL_1);
- SM_ASSERT(LEVEL_1, (ShmDiskQueues!=NULL));
-
- process_identity.me = SERVER_PROC;
- process_identity.other = (1 - process_identity.me);
-
- /*
- * get the semaphores. First try w/o creating it.
- */
- #define SEMPERM 0600 /* owner r/w */
-
- SemKey = IPC_PRIVATE;
-
- SemId = semget(SemKey, NumVolumes, SEMPERM);
- if((SemId < 0) && (errno == ENOENT)) {
- /*
- * SemId does not exist. Try to create it.
- */
- TRPRINT(TR_INIT, TR_LEVEL_1, ("Couldn't get SemId w/o IPC_CREAT"));
- errno = 0;
- SemId = semget(SemKey, NumVolumes, SEMPERM | IPC_CREAT);
- }
- if(SemId < 0) {
- TRPRINT(TR_INIT, TR_LEVEL_1, ("Couldn't get SemId with IPC_CREAT"));
- fprintf(sm_ErrorStream, "SERVER error: could not allocate shared memory.\n");
- fprintf(sm_ErrorStream, "\tUse ipcs and ipcrm to free old shared memory segments.\n");
- SM_ERROR(TYPE_STOP, errno);
- }
- TRPRINT(TR_INIT, TR_LEVEL_1, ("SemId 0x%x, key 0x%x", SemId, SemKey));
-
- /*
- * the semaphore for replies to the server from the disk processes
- */
- Replies = (MUTEX *)ShmReplies;
- bzero((char*)Replies, sizeof Replies);
- INIT_MUTEX_MAGIC(Replies);
-
- } /* initializeQueues */
-
-